E.debug = {};

var $DO = E.debug.printObject = function(args) {
    var bodyWidth = document.body.scrollWidth;
    var bodyHeight = document.body.scrollHeight;
    var table = "<table border='2'>";

    for ( var i in args) {
        table += "<tr><td>" + i + "</td><td>" + args[i] + "</td></tr>";
    }

    table += "</table>";

    var div = document.createElement("DIV");
    div.id = "debugDiv";
    div.style.zindex = 99999;
    div.style.paddingLeft = "400px";
    div.style.paddingTop = "100px";
    div.style.width = bodyWidth + "px";
    div.style.height = bodyHeight + "px";
    div.style.left = 0;
    div.style.top = 0;
    div.style.background = '#cdcdcd';
    div.style.opacity = 0.9;
    div.style.position = "absolute";
    div.innerHTML = table;

    document.getElementsByTagName("body").item(0).appendChild(div);
    document.addEventListener("keypress", E.debug.close);
}

var $DH = E.debug.printHTML = function(args) {
    var bodyWidth = document.body.scrollWidth;
    var bodyHeight = document.body.scrollHeight;
    var _txt = "<textarea rows='50' cols='200'>" + args + "</textarea>";
    var div = document.createElement("DIV");
    div.id = "debugDiv";
    div.style.zindex = 99999;
    div.style.paddingLeft = "400px";
    div.style.paddingTop = "100px";
    div.style.width = bodyWidth + "px";
    div.style.height = bodyHeight + "px";
    div.style.left = 0;
    div.style.top = 0;
    div.style.background = '#cdcdcd';
    div.style.opacity = 0.9;
    div.style.position = "absolute";
    div.innerHTML = _txt;

    document.getElementsByTagName("body").item(0).appendChild(div);
    document.addEventListener("keypress", E.debug.close);
}

E.debug.close = function(e) {
    if (e.which == 13 || e.which == 32) {
        var debugDiv = document.getElementById("debugDiv");
        debugDiv.innerHTML = null;
        document.getElementsByTagName("body").item(0).removeChild(debugDiv);
    }
};
